package com.wanxin.wb.common.support;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.support.RequestContextUtils;




public class SystemLanguageFilter implements Filter {

	@Autowired
	private CookieLocaleResolver cookieLocaleResolver;
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, cookieLocaleResolver);
		Locale locale = RequestContextUtils.getLocale((HttpServletRequest) request);
		request.setAttribute("easeyeI18nLang", locale.getLanguage());
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
	}

}
